package com.op.studyingliteapp.fragment.resource;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.op.studyingliteapp.R;

/**
 * 
 * @author handsome
 *
 */
public class ResourceListAdapter extends BaseAdapter {

	public ArrayList<ResourceCellData> list;
	public Context mContext;

	public ResourceListAdapter(Context mContext,
			ArrayList<ResourceCellData> list) {
		this.list = list;
		this.mContext = mContext;
		list.add(new ResourceCellData(R.drawable.icon_resource, "课程PPT ",
				"6月13日   10:53"));
		list.add(new ResourceCellData(R.drawable.icon_resource, "上机实验 ",
				"6月13日   10:53"));
		list.add(new ResourceCellData(R.drawable.icon_resource, "电子书",
				"6月13日   10:53"));
		list.add(new ResourceCellData(R.drawable.icon_resource, "学习资料",
				"6月13日   10:53"));
	}

	public Context getContext() {
		return this.mContext;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public ResourceCellData getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout fl = null;
		if (convertView != null) {
			fl = (LinearLayout) convertView;
		} else {
			fl = (LinearLayout) LayoutInflater.from(getContext()).inflate(
					R.layout.item_resource, parent, false);
		}
		ResourceCellData data = getItem(position);

		ImageView resourceView = (ImageView) fl
				.findViewById(R.id.resource_image);
		TextView resourceName = (TextView) fl.findViewById(R.id.resource_text);
		TextView resourceTime = (TextView) fl.findViewById(R.id.resource_time);
		resourceView.setBackgroundResource(data.getImage());
		resourceName.setText(data.getName());
		resourceTime.setText(data.getTime());

		return fl;
	}

}
